<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>个人信息</title>
    <link rel="icon" th:href="@{/img/icon.ico}">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/layuimini/css/public.css}" media="all">
    <style>
        .layui-form-item .layui-input-company {
            width: auto;padding-right: 10px;line-height: 38px;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <form class="layui-form" action="" lay-filter="formDemo">
            <div class="layui-form layuimini-form">
                <input type="hidden" name="id">
                <div class="layui-form-item">
                    <label class="layui-form-label required">账户</label>
                    <div class="layui-input-block">
                        <input type="text" name="account" lay-verify="required" lay-reqtext="请输入用户账号" placeholder="请输入" class="layui-input" disabled>
                        <tip>用户登录账号，不支持修改</tip>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">手机号</label>
                    <div class="layui-input-block">
                        <input type="text" name="phone" lay-verify="required|phone" lay-reqtext="请输入手机号" placeholder="请输入" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">姓名</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" lay-verify="required" lay-reqtext="请输入用户姓名" placeholder="请输入" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">头像</label>
                    <div class="layui-input-block">
                        <input type="hidden" name="avatar">
                        <div style="height: 100px;width: 100px;position: relative;">
                            <img th:src="${data.avatar}" alt="" id="pic-img" style="height: 100%;width: 100%;position: absolute;left: 0;top: 0;border: 1px solid #1E9FFF;border-radius: 50%">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">性别</label>
                    <div class="layui-input-block">
                        <select name="sex">
                            <option value="">请选择</option>
                            <option th:each="item : ${sex}" th:value="${item.code}" th:text="${item.name}"></option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">邮箱地址</label>
                    <div class="layui-input-block">
                        <input type="text" name="email" placeholder="请输入" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-submit lay-filter="saveBtn"> 保存 </button>
                        <tip>修改个人信息，下次登录生效</tip>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<script type="text/javascript" th:src="@{/js/jquery-3.2.0.min.js}"></script>
<script type="text/javascript" th:src="@{/layui/layui.js}"></script>
<script type="text/javascript" th:src="@{/js/common-table.js}"></script>

<script type="text/javascript" th:inline="javascript">

    layui.use(['form', 'layer', 'croppers'], function () {
        var $ = layui.jquery,
            form = layui.form,
            layer = layui.layer,
            croppers = layui.croppers;

        var ctxPath = /*[[@{/}]]*/;
        var baseUrl = ctxPath + 'sys/sys-user-info/';

        form.val("formDemo", [[${data}]]);

        croppers.render({
            elem: '#pic-img'
            ,saveW: 150     //保存宽度
            ,saveH: 150
            ,mark: 1/1    //选取比例
            ,area: '900px'  //弹窗宽度
            ,url: ctxPath + "sys/sys-minio/layuiUploadFile"  //图片上传接口返回和（layui 的upload 模块）返回的JOSN一样
            ,done: function(url){
                $('input[name="avatar"]').val(url);
                $("#pic-img").attr('src', url);
            }
        });

        // 监听提交
        form.on('submit(saveBtn)', function (res) {
            var data = res.field;
            Asurplus.post({
                url: baseUrl + 'info',
                data: JSON.stringify(data)
            }, () => {
                setTimeout(function () {
                    window.location.reload();
                }, 1500)
            });
            return false;
        });
    });
</script>
</body>
</html>